package top.jfunc.common.db.data;

import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ForkJoinPool;

/**
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
 * @since 1.0 2022/11/12 15:57
 */
public class MultiThreadHandler {
  private Executor executor = ForkJoinPool.commonPool();
  private final List<Runnable> runnableList;

  public MultiThreadHandler(List<Runnable> runnableList) {
    this.runnableList = runnableList;
  }

  public MultiThreadHandler addTask(Runnable runnable) {
    runnableList.add(runnable);
    return this;
  }

  public void run() {
    for (Runnable runnable : runnableList) {
      executor.execute(runnable);
    }
  }

}
